package com.qffx.moviebase.view;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.qffx.moviebase.R;
import com.qffx.moviebase.adapter.find.FindMovieAdapter;
import com.qffx.moviebase.bean.find.FindMovieEntity;
import com.qffx.moviebase.bean.find.findmovie.BaseEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieCastEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieCommentListEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieFilmResourceEntity;
import com.qffx.moviebase.bean.find.findmovie.MoviePhotoEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieRelationArticleEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieSummaryEntity;
import com.qffx.moviebase.bean.find.findmovie.MovieTrailerEntity;
import com.qffx.moviebase.presenter.FindMoviePresenter;
import com.qffx.moviebase.view.impl.FindMovieView;

import java.util.ArrayList;
import java.util.List;

public class FindMovieActivity extends AppCompatActivity implements FindMovieView {
    private FindMoviePresenter present;
    private RecyclerView recycle;
    private List<BaseEntity> list;
    private FindMovieAdapter adapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_find_movie);
        init();

    }


    private void init() {
        recycle = (RecyclerView) findViewById(R.id.find_movie_recycle);
        list = new ArrayList<>();
        Intent intent = getIntent();
        present = new FindMoviePresenter(this);
        String id = intent.getStringExtra("id");
        Toast.makeText(this, id, Toast.LENGTH_SHORT).show();
        //
        present.getData(id);
        LinearLayoutManager manager = new LinearLayoutManager(this);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        recycle.setLayoutManager(manager);
        adapter = new FindMovieAdapter(list, this);
        recycle.setAdapter(adapter);
    }
    //
    @Override
    public void setDate(FindMovieEntity entity) {
        //电影信息
        MovieFilmResourceEntity entity1 = new MovieFilmResourceEntity();
        entity1.setBean(entity.getFilmResources());
        list.add(entity1);
        //剧情简介
        MovieSummaryEntity entity2 = new MovieSummaryEntity();
        entity2.setSummary(entity.getFilmResources().getSummary());
        list.add(entity2);
        //演员
        MovieCastEntity entity3 = new MovieCastEntity();
        entity3.setCasts(entity.getMovieInfo().get_source().getCasts());
        entity3.setDirectors(entity.getMovieInfo().get_source().getDirectors());
        list.add(entity3);
        //预告片
        MovieTrailerEntity entity4 = new MovieTrailerEntity();
        if (entity.getMovieInfo().get_source().getTrailers().size() > 0) {
            entity4.setBean(entity.getMovieInfo().get_source().getTrailers());
            list.add(entity4);
        }
        //剧照
        MoviePhotoEntity entity5 = new MoviePhotoEntity();
        if (entity.getMovieInfo().get_source().getStage_photos().size() > 0) {
            entity5.setUrl(entity.getMovieInfo().get_source().getStage_photos());
            list.add(entity5);
        }
        //相关文章
        MovieRelationArticleEntity entity6 = new MovieRelationArticleEntity();
        entity6.setList(entity.getRelationArticle());
        list.add(entity6);
        //用户评论
        MovieCommentListEntity entity7 = new MovieCommentListEntity();
        entity7.setList(entity.getCommentList());
        list.add(entity7);
        Toast.makeText(this, list.size()+"", Toast.LENGTH_SHORT).show();
        adapter.notifyDataSetChanged();
    }
}
